<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="E3," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="不悔经行处，只恨太匆匆。  redis安装方法安装redis需要c语言的编译环境1yum install gcc-c++ 12345第一步：redis的源码包上传到linux系统。第二步：解压缩redis。第三步：编译。进入redis源码目录。make 第四步：安装。make install PREFIX=/usr/local/redisPREFIX参数指定redis的安装目录。一般软件安装到/">
<meta name="keywords" content="E3">
<meta property="og:type" content="article">
<meta property="og:title" content="E3-four">
<meta property="og:url" content="http://yoursite.com/2017/06/26/E3-four/index.html">
<meta property="og:site_name" content="JokerLiang">
<meta property="og:description" content="不悔经行处，只恨太匆匆。  redis安装方法安装redis需要c语言的编译环境1yum install gcc-c++ 12345第一步：redis的源码包上传到linux系统。第二步：解压缩redis。第三步：编译。进入redis源码目录。make 第四步：安装。make install PREFIX=/usr/local/redisPREFIX参数指定redis的安装目录。一般软件安装到/">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-06-26T08:41:54.814Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="E3-four">
<meta name="twitter:description" content="不悔经行处，只恨太匆匆。  redis安装方法安装redis需要c语言的编译环境1yum install gcc-c++ 12345第一步：redis的源码包上传到linux系统。第二步：解压缩redis。第三步：编译。进入redis源码目录。make 第四步：安装。make install PREFIX=/usr/local/redisPREFIX参数指定redis的安装目录。一般软件安装到/">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/06/26/E3-four/"/>





  <title> E3-four | JokerLiang </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  








  <div style="display: none;">
    <script src="//s95.cnzz.com/z_stat.php?id=1260895995&web_id=1260895995" language="JavaScript"></script>
  </div>





  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">JokerLiang</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">永远年轻，永远热泪盈眶。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>


    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/06/26/E3-four/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="JokerLiang">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/me.jpg">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="JokerLiang">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="JokerLiang" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                E3-four
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-06-26T16:41:05+08:00">
                2017-06-26
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/E3/" itemprop="url" rel="index">
                    <span itemprop="name">E3</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <blockquote>
<p>&#x4E0D;&#x6094;&#x7ECF;&#x884C;&#x5904;&#xFF0C;&#x53EA;&#x6068;&#x592A;&#x5306;&#x5306;&#x3002;</p>
</blockquote>
<h2 id="redis&#x5B89;&#x88C5;&#x65B9;&#x6CD5;"><a href="#redis&#x5B89;&#x88C5;&#x65B9;&#x6CD5;" class="headerlink" title="redis&#x5B89;&#x88C5;&#x65B9;&#x6CD5;"></a>redis&#x5B89;&#x88C5;&#x65B9;&#x6CD5;</h2><h3 id="&#x5B89;&#x88C5;redis&#x9700;&#x8981;c&#x8BED;&#x8A00;&#x7684;&#x7F16;&#x8BD1;&#x73AF;&#x5883;"><a href="#&#x5B89;&#x88C5;redis&#x9700;&#x8981;c&#x8BED;&#x8A00;&#x7684;&#x7F16;&#x8BD1;&#x73AF;&#x5883;" class="headerlink" title="&#x5B89;&#x88C5;redis&#x9700;&#x8981;c&#x8BED;&#x8A00;&#x7684;&#x7F16;&#x8BD1;&#x73AF;&#x5883;"></a>&#x5B89;&#x88C5;redis&#x9700;&#x8981;c&#x8BED;&#x8A00;&#x7684;&#x7F16;&#x8BD1;&#x73AF;&#x5883;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install gcc-c++</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#x7B2C;&#x4E00;&#x6B65;&#xFF1A;redis&#x7684;&#x6E90;&#x7801;&#x5305;&#x4E0A;&#x4F20;&#x5230;linux&#x7CFB;&#x7EDF;&#x3002;</span><br><span class="line">&#x7B2C;&#x4E8C;&#x6B65;&#xFF1A;&#x89E3;&#x538B;&#x7F29;redis&#x3002;</span><br><span class="line">&#x7B2C;&#x4E09;&#x6B65;&#xFF1A;&#x7F16;&#x8BD1;&#x3002;&#x8FDB;&#x5165;redis&#x6E90;&#x7801;&#x76EE;&#x5F55;&#x3002;make </span><br><span class="line">&#x7B2C;&#x56DB;&#x6B65;&#xFF1A;&#x5B89;&#x88C5;&#x3002;make install PREFIX=/usr/local/redis</span><br><span class="line">PREFIX&#x53C2;&#x6570;&#x6307;&#x5B9A;redis&#x7684;&#x5B89;&#x88C5;&#x76EE;&#x5F55;&#x3002;&#x4E00;&#x822C;&#x8F6F;&#x4EF6;&#x5B89;&#x88C5;&#x5230;/usr&#x76EE;&#x5F55;&#x4E0B;</span><br></pre></td></tr></table></figure>
<a id="more"></a>
<h3 id="&#x542F;&#x52A8;"><a href="#&#x542F;&#x52A8;" class="headerlink" title="&#x542F;&#x52A8;"></a>&#x542F;&#x52A8;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&#x628A;/root/redis-3.0.0/redis.conf&#x590D;&#x5236;&#x5230;/usr/local/redis/bin&#x76EE;&#x5F55;&#x4E0B;</span><br><span class="line">[root@localhost redis-3.0.0]# cp redis.conf /usr/local/redis/bin/</span><br><span class="line">&#x628A;daemonize &#x6539;&#x4E3A;yes</span><br><span class="line">&#x542F;&#x52A8; &#xFF1A;  ./redis-server redis.conf</span><br></pre></td></tr></table></figure>
<h2 id="redis&#x96C6;&#x7FA4;&#x7684;&#x642D;&#x5EFA;"><a href="#redis&#x96C6;&#x7FA4;&#x7684;&#x642D;&#x5EFA;" class="headerlink" title="redis&#x96C6;&#x7FA4;&#x7684;&#x642D;&#x5EFA;"></a>redis&#x96C6;&#x7FA4;&#x7684;&#x642D;&#x5EFA;</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&#x7B2C;&#x4E00;&#x6B65;&#xFF1A;&#x521B;&#x5EFA;6&#x4E2A;redis&#x5B9E;&#x4F8B;&#xFF0C;&#x6BCF;&#x4E2A;&#x5B9E;&#x4F8B;&#x8FD0;&#x884C;&#x5728;&#x4E0D;&#x540C;&#x7684;&#x7AEF;&#x53E3;&#x3002;&#x9700;&#x8981;&#x4FEE;&#x6539;redis.conf&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x3002;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x8FD8;&#x9700;&#x8981;&#x628A;cluster-enabled yes&#x524D;&#x7684;&#x6CE8;&#x91CA;&#x53BB;&#x6389;&#x3002;</span><br><span class="line">&#x7B2C;&#x4E8C;&#x6B65;&#xFF1A;&#x542F;&#x52A8;&#x6BCF;&#x4E2A;redis&#x5B9E;&#x4F8B;&#x3002;</span><br><span class="line">&#x7B2C;&#x4E09;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;ruby&#x811A;&#x672C;&#x642D;&#x5EFA;&#x96C6;&#x7FA4;&#x3002;</span><br><span class="line">./redis-trib.rb create --replicas 1 192.168.25.153:7001 192.168.25.153:7002 192.168.25.153:7003 192.168.25.153:7004 192.168.25.153:7005 192.168.25.153:7006</span><br></pre></td></tr></table></figure>
<h2 id="&#x9700;&#x8981;&#x5B89;&#x88C5;ruby&#x7684;&#x73AF;&#x5883;"><a href="#&#x9700;&#x8981;&#x5B89;&#x88C5;ruby&#x7684;&#x73AF;&#x5883;" class="headerlink" title="&#x9700;&#x8981;&#x5B89;&#x88C5;ruby&#x7684;&#x73AF;&#x5883;"></a>&#x9700;&#x8981;&#x5B89;&#x88C5;ruby&#x7684;&#x73AF;&#x5883;</h2><h2 id="Jedis&#x4F7F;&#x7528;&#x65B9;&#x6CD5;"><a href="#Jedis&#x4F7F;&#x7528;&#x65B9;&#x6CD5;" class="headerlink" title="Jedis&#x4F7F;&#x7528;&#x65B9;&#x6CD5;"></a>Jedis&#x4F7F;&#x7528;&#x65B9;&#x6CD5;</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">	<span class="meta">@Test</span></span><br><span class="line">	<span class="comment">//&#x8FDE;&#x63A5;&#x5355;&#x673A;&#x7248;&#xFF0C;&#x666E;&#x901A;&#x65B9;&#x5F0F;</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">fun</span><span class="params">()</span> </span>{</span><br><span class="line">		Jedis jedis = <span class="keyword">new</span> Jedis(<span class="string">&quot;192.168.25.128&quot;</span>,<span class="number">6379</span>); </span><br><span class="line">		jedis.set(<span class="string">&quot;joker&quot;</span>, <span class="string">&quot;liang&quot;</span>);</span><br><span class="line">		String joker = jedis.get(<span class="string">&quot;joker&quot;</span>);</span><br><span class="line">		System.out.println(joker);</span><br><span class="line">		jedis.close();</span><br><span class="line">	}</span><br><span class="line">	</span><br><span class="line">	<span class="meta">@Test</span></span><br><span class="line">	<span class="comment">//&#x8FDE;&#x63A5;&#x5355;&#x673A;&#x7248;&#xFF0C;&#x4F7F;&#x7528;&#x94FE;&#x63A5;&#x6C60;</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">fun1</span><span class="params">()</span></span>{</span><br><span class="line">		JedisPool pool = <span class="keyword">new</span> JedisPool(<span class="string">&quot;192.168.25.128&quot;</span>, <span class="number">6379</span>);</span><br><span class="line">		Jedis jedis = pool.getResource();</span><br><span class="line">		String joker = jedis.get(<span class="string">&quot;joker&quot;</span>);</span><br><span class="line">		System.out.println(joker);</span><br><span class="line">		jedis.close();</span><br><span class="line">		pool.close();</span><br><span class="line">	}</span><br><span class="line">	</span><br><span class="line">	<span class="meta">@Test</span></span><br><span class="line">	<span class="comment">//&#x8FDE;&#x63A5;&#x96C6;&#x7FA4;</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">fun2</span><span class="params">()</span></span>{</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E00;&#x6B65;&#xFF1A;&#x4F7F;&#x7528;JedisCluster&#x5BF9;&#x8C61;&#x3002;&#x9700;&#x8981;&#x4E00;&#x4E2A;Set&lt;HostAndPort&gt;&#x53C2;&#x6570;&#x3002;Redis&#x8282;&#x70B9;&#x7684;&#x5217;&#x8868;&#x3002;</span></span><br><span class="line">		Set&lt;HostAndPort&gt; nodes = <span class="keyword">new</span> HashSet&lt;&gt;();</span><br><span class="line">		nodes.add(<span class="keyword">new</span> HostAndPort(<span class="string">&quot;192.168.25.128&quot;</span>, <span class="number">7001</span>));</span><br><span class="line">		nodes.add(<span class="keyword">new</span> HostAndPort(<span class="string">&quot;192.168.25.128&quot;</span>, <span class="number">7002</span>));</span><br><span class="line">		nodes.add(<span class="keyword">new</span> HostAndPort(<span class="string">&quot;192.168.25.128&quot;</span>, <span class="number">7003</span>));</span><br><span class="line">		nodes.add(<span class="keyword">new</span> HostAndPort(<span class="string">&quot;192.168.25.128&quot;</span>, <span class="number">7004</span>));</span><br><span class="line">		nodes.add(<span class="keyword">new</span> HostAndPort(<span class="string">&quot;192.168.25.128&quot;</span>, <span class="number">7005</span>));</span><br><span class="line">		nodes.add(<span class="keyword">new</span> HostAndPort(<span class="string">&quot;192.168.25.128&quot;</span>, <span class="number">7006</span>));</span><br><span class="line">		JedisCluster jedisCluster = <span class="keyword">new</span> JedisCluster(nodes);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E8C;&#x6B65;&#xFF1A;&#x76F4;&#x63A5;&#x4F7F;&#x7528;JedisCluster&#x5BF9;&#x8C61;&#x64CD;&#x4F5C;redis&#x3002;&#x5728;&#x7CFB;&#x7EDF;&#x4E2D;&#x5355;&#x4F8B;&#x5B58;&#x5728;&#x3002;</span></span><br><span class="line">		jedisCluster.set(<span class="string">&quot;joker&quot;</span>, <span class="string">&quot;JokerLiang&quot;</span>);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x4E09;&#x6B65;&#xFF1A;&#x6253;&#x5370;&#x7ED3;&#x679C;</span></span><br><span class="line">		String joker = jedisCluster.get(<span class="string">&quot;joker&quot;</span>);</span><br><span class="line">		System.out.println(joker);</span><br><span class="line"><span class="comment">//		&#x7B2C;&#x56DB;&#x6B65;&#xFF1A;&#x7CFB;&#x7EDF;&#x5173;&#x95ED;&#x524D;&#xFF0C;&#x5173;&#x95ED;JedisCluster&#x5BF9;&#x8C61;</span></span><br><span class="line">		jedisCluster.close();</span><br><span class="line">	}</span><br></pre></td></tr></table></figure>
<h2 id="&#x9879;&#x76EE;&#x4E2D;&#x5F15;&#x5165;redis&#x5B9E;&#x73B0;&#x7F13;&#x5B58;"><a href="#&#x9879;&#x76EE;&#x4E2D;&#x5F15;&#x5165;redis&#x5B9E;&#x73B0;&#x7F13;&#x5B58;" class="headerlink" title="&#x9879;&#x76EE;&#x4E2D;&#x5F15;&#x5165;redis&#x5B9E;&#x73B0;&#x7F13;&#x5B58;"></a>&#x9879;&#x76EE;&#x4E2D;&#x5F15;&#x5165;redis&#x5B9E;&#x73B0;&#x7F13;&#x5B58;</h2><h3 id="Maven&#x52A0;&#x5165;&#x4F9D;&#x8D56;"><a href="#Maven&#x52A0;&#x5165;&#x4F9D;&#x8D56;" class="headerlink" title="Maven&#x52A0;&#x5165;&#x4F9D;&#x8D56;"></a>Maven&#x52A0;&#x5165;&#x4F9D;&#x8D56;</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">&lt;!-- redis --&gt;</span><br><span class="line">&lt;dependency&gt;</span><br><span class="line">	&lt;groupId&gt;redis.clients&lt;/groupId&gt;</span><br><span class="line">	&lt;artifactId&gt;jedis&lt;/artifactId&gt;</span><br><span class="line">&lt;/dependency&gt;</span><br></pre></td></tr></table></figure>
<h3 id="&#x4E09;&#x4E2A;&#x5DE5;&#x5177;&#x7C7B;"><a href="#&#x4E09;&#x4E2A;&#x5DE5;&#x5177;&#x7C7B;" class="headerlink" title="&#x4E09;&#x4E2A;&#x5DE5;&#x5177;&#x7C7B;"></a>&#x4E09;&#x4E2A;&#x5DE5;&#x5177;&#x7C7B;</h3><h4 id="JedisClient"><a href="#JedisClient" class="headerlink" title="JedisClient"></a>JedisClient</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> cn.e3mall.common.jedis;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">JedisClient</span> </span>{</span><br><span class="line"></span><br><span class="line">	<span class="function">String <span class="title">set</span><span class="params">(String key, String value)</span></span>;</span><br><span class="line">	<span class="function">String <span class="title">get</span><span class="params">(String key)</span></span>;</span><br><span class="line">	<span class="function">Boolean <span class="title">exists</span><span class="params">(String key)</span></span>;</span><br><span class="line">	<span class="function">Long <span class="title">expire</span><span class="params">(String key, <span class="keyword">int</span> seconds)</span></span>;</span><br><span class="line">	<span class="function">Long <span class="title">ttl</span><span class="params">(String key)</span></span>;</span><br><span class="line">	<span class="function">Long <span class="title">incr</span><span class="params">(String key)</span></span>;</span><br><span class="line">	<span class="function">Long <span class="title">hset</span><span class="params">(String key, String field, String value)</span></span>;</span><br><span class="line">	<span class="function">String <span class="title">hget</span><span class="params">(String key, String field)</span></span>;</span><br><span class="line">	<span class="function">Long <span class="title">hdel</span><span class="params">(String key, String... field)</span></span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h4 id="JedisClientCluster"><a href="#JedisClientCluster" class="headerlink" title="JedisClientCluster"></a>JedisClientCluster</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> cn.e3mall.common.jedis;</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> redis.clients.jedis.JedisCluster;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">JedisClientCluster</span> <span class="keyword">implements</span> <span class="title">JedisClient</span> </span>{</span><br><span class="line">	</span><br><span class="line"> </span><br><span class="line">	<span class="keyword">private</span> JedisCluster jedisCluster;</span><br><span class="line">	</span><br><span class="line">	<span class="function"><span class="keyword">public</span> JedisCluster <span class="title">getJedisCluster</span><span class="params">()</span> </span>{</span><br><span class="line">		<span class="keyword">return</span> jedisCluster;</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setJedisCluster</span><span class="params">(JedisCluster jedisCluster)</span> </span>{</span><br><span class="line">		<span class="keyword">this</span>.jedisCluster = jedisCluster;</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> String <span class="title">set</span><span class="params">(String key, String value)</span> </span>{</span><br><span class="line">		<span class="keyword">return</span> jedisCluster.set(key, value);</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> String <span class="title">get</span><span class="params">(String key)</span> </span>{</span><br><span class="line">		<span class="keyword">return</span> jedisCluster.get(key);</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> Boolean <span class="title">exists</span><span class="params">(String key)</span> </span>{</span><br><span class="line">		<span class="keyword">return</span> jedisCluster.exists(key);</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> Long <span class="title">expire</span><span class="params">(String key, <span class="keyword">int</span> seconds)</span> </span>{</span><br><span class="line">		<span class="keyword">return</span> jedisCluster.expire(key, seconds);</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> Long <span class="title">ttl</span><span class="params">(String key)</span> </span>{</span><br><span class="line">		<span class="keyword">return</span> jedisCluster.ttl(key);</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> Long <span class="title">incr</span><span class="params">(String key)</span> </span>{</span><br><span class="line">		<span class="keyword">return</span> jedisCluster.incr(key);</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> Long <span class="title">hset</span><span class="params">(String key, String field, String value)</span> </span>{</span><br><span class="line">		<span class="keyword">return</span> jedisCluster.hset(key, field, value);</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> String <span class="title">hget</span><span class="params">(String key, String field)</span> </span>{</span><br><span class="line">		<span class="keyword">return</span> jedisCluster.hget(key, field);</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> Long <span class="title">hdel</span><span class="params">(String key, String... field)</span> </span>{</span><br><span class="line">		<span class="keyword">return</span> jedisCluster.hdel(key, field);</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h4 id="JedisClientPool"><a href="#JedisClientPool" class="headerlink" title="JedisClientPool"></a>JedisClientPool</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> cn.e3mall.common.jedis;</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> redis.clients.jedis.Jedis;</span><br><span class="line"><span class="keyword">import</span> redis.clients.jedis.JedisPool;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">JedisClientPool</span> <span class="keyword">implements</span> <span class="title">JedisClient</span> </span>{</span><br><span class="line">	</span><br><span class="line">	 </span><br><span class="line">	<span class="keyword">private</span> JedisPool jedisPool;</span><br><span class="line"></span><br><span class="line">	<span class="function"><span class="keyword">public</span> JedisPool <span class="title">getJedisPool</span><span class="params">()</span> </span>{</span><br><span class="line">		<span class="keyword">return</span> jedisPool;</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setJedisPool</span><span class="params">(JedisPool jedisPool)</span> </span>{</span><br><span class="line">		<span class="keyword">this</span>.jedisPool = jedisPool;</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> String <span class="title">set</span><span class="params">(String key, String value)</span> </span>{</span><br><span class="line">		Jedis jedis = jedisPool.getResource();</span><br><span class="line">		String result = jedis.set(key, value);</span><br><span class="line">		jedis.close();</span><br><span class="line">		<span class="keyword">return</span> result;</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> String <span class="title">get</span><span class="params">(String key)</span> </span>{</span><br><span class="line">		Jedis jedis = jedisPool.getResource();</span><br><span class="line">		String result = jedis.get(key);</span><br><span class="line">		jedis.close();</span><br><span class="line">		<span class="keyword">return</span> result;</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> Boolean <span class="title">exists</span><span class="params">(String key)</span> </span>{</span><br><span class="line">		Jedis jedis = jedisPool.getResource();</span><br><span class="line">		Boolean result = jedis.exists(key);</span><br><span class="line">		jedis.close();</span><br><span class="line">		<span class="keyword">return</span> result;</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> Long <span class="title">expire</span><span class="params">(String key, <span class="keyword">int</span> seconds)</span> </span>{</span><br><span class="line">		Jedis jedis = jedisPool.getResource();</span><br><span class="line">		Long result = jedis.expire(key, seconds);</span><br><span class="line">		jedis.close();</span><br><span class="line">		<span class="keyword">return</span> result;</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> Long <span class="title">ttl</span><span class="params">(String key)</span> </span>{</span><br><span class="line">		Jedis jedis = jedisPool.getResource();</span><br><span class="line">		Long result = jedis.ttl(key);</span><br><span class="line">		jedis.close();</span><br><span class="line">		<span class="keyword">return</span> result;</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> Long <span class="title">incr</span><span class="params">(String key)</span> </span>{</span><br><span class="line">		Jedis jedis = jedisPool.getResource();</span><br><span class="line">		Long result = jedis.incr(key);</span><br><span class="line">		jedis.close();</span><br><span class="line">		<span class="keyword">return</span> result;</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> Long <span class="title">hset</span><span class="params">(String key, String field, String value)</span> </span>{</span><br><span class="line">		Jedis jedis = jedisPool.getResource();</span><br><span class="line">		Long result = jedis.hset(key, field, value);</span><br><span class="line">		jedis.close();</span><br><span class="line">		<span class="keyword">return</span> result;</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> String <span class="title">hget</span><span class="params">(String key, String field)</span> </span>{</span><br><span class="line">		Jedis jedis = jedisPool.getResource();</span><br><span class="line">		String result = jedis.hget(key, field);</span><br><span class="line">		jedis.close();</span><br><span class="line">		<span class="keyword">return</span> result;</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">	<span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> Long <span class="title">hdel</span><span class="params">(String key, String... field)</span> </span>{</span><br><span class="line">		Jedis jedis = jedisPool.getResource();</span><br><span class="line">		Long result = jedis.hdel(key, field);</span><br><span class="line">		jedis.close();</span><br><span class="line">		<span class="keyword">return</span> result;</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h3 id="Spring&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x2013;&#x53EF;&#x4EE5;&#x968F;&#x610F;&#x5207;&#x6362;&#x662F;&#x96C6;&#x7FA4;&#x8FD8;&#x662F;&#x5355;&#x4E2A;"><a href="#Spring&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x2013;&#x53EF;&#x4EE5;&#x968F;&#x610F;&#x5207;&#x6362;&#x662F;&#x96C6;&#x7FA4;&#x8FD8;&#x662F;&#x5355;&#x4E2A;" class="headerlink" title="Spring&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x2013;&#x53EF;&#x4EE5;&#x968F;&#x610F;&#x5207;&#x6362;&#x662F;&#x96C6;&#x7FA4;&#x8FD8;&#x662F;&#x5355;&#x4E2A;"></a>Spring&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x2013;&#x53EF;&#x4EE5;&#x968F;&#x610F;&#x5207;&#x6362;&#x662F;&#x96C6;&#x7FA4;&#x8FD8;&#x662F;&#x5355;&#x4E2A;</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="comment">&lt;!-- &#x8FDE;&#x63A5;&#x5355;&#x673A;&#x7248; --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;jedisClientPool&quot;</span> <span class="attr">class</span>=<span class="string">&quot;cn.e3mall.common.jedis.JedisClientPool&quot;</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;jedisPool&quot;</span> <span class="attr">ref</span>=<span class="string">&quot;jedisPool&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">property</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;jedisPool&quot;</span> <span class="attr">class</span>=<span class="string">&quot;redis.clients.jedis.JedisPool&quot;</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">name</span>=<span class="string">&quot;host&quot;</span> <span class="attr">value</span>=<span class="string">&quot;192.168.25.128&quot;</span>/&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">name</span>=<span class="string">&quot;port&quot;</span> <span class="attr">value</span>=<span class="string">&quot;6379&quot;</span>/&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">&lt;!-- &#x96C6;&#x7FA4;&#x7248;&#x672C; --&gt;</span></span><br><span class="line">  </span><br><span class="line"><span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">&quot;jedisClientPool&quot;</span> <span class="attr">class</span>=<span class="string">&quot;cn.e3mall.common.jedis.JedisClientPool&quot;</span>&gt;</span></span><br><span class="line">		 <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">&quot;jedisCluster&quot;</span> <span class="attr">ref</span>=<span class="string">&quot;jedisCluster&quot;</span> /&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span> = <span class="string">&quot;jedisCluster&quot;</span> <span class="attr">class</span>=<span class="string">&quot;redis.clients.jedis.JedisCluster&quot;</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">name</span>=<span class="string">&quot;nodes&quot;</span> &gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">set</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">bean</span> <span class="attr">class</span>=<span class="string">&quot;redis.clients.jedis.HostAndPort&quot;</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">name</span>=<span class="string">&quot;host&quot;</span> <span class="attr">value</span>=<span class="string">&quot;192.168.25.128&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">name</span>=<span class="string">&quot;post&quot;</span>  <span class="attr">value</span>=<span class="string">&quot;7001&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">bean</span> <span class="attr">class</span>=<span class="string">&quot;redis.clients.jedis.HostAndPort&quot;</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">name</span>=<span class="string">&quot;host&quot;</span> <span class="attr">value</span>=<span class="string">&quot;192.168.25.128&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">name</span>=<span class="string">&quot;post&quot;</span>  <span class="attr">value</span>=<span class="string">&quot;7002&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">bean</span> <span class="attr">class</span>=<span class="string">&quot;redis.clients.jedis.HostAndPort&quot;</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">name</span>=<span class="string">&quot;host&quot;</span> <span class="attr">value</span>=<span class="string">&quot;192.168.25.128&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">name</span>=<span class="string">&quot;post&quot;</span>  <span class="attr">value</span>=<span class="string">&quot;7003&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">bean</span> <span class="attr">class</span>=<span class="string">&quot;redis.clients.jedis.HostAndPort&quot;</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">name</span>=<span class="string">&quot;host&quot;</span> <span class="attr">value</span>=<span class="string">&quot;192.168.25.128&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">name</span>=<span class="string">&quot;post&quot;</span>  <span class="attr">value</span>=<span class="string">&quot;7004&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">bean</span> <span class="attr">class</span>=<span class="string">&quot;redis.clients.jedis.HostAndPort&quot;</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">name</span>=<span class="string">&quot;host&quot;</span> <span class="attr">value</span>=<span class="string">&quot;192.168.25.128&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">name</span>=<span class="string">&quot;post&quot;</span>  <span class="attr">value</span>=<span class="string">&quot;7005&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">bean</span> <span class="attr">class</span>=<span class="string">&quot;redis.clients.jedis.HostAndPort&quot;</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">name</span>=<span class="string">&quot;host&quot;</span> <span class="attr">value</span>=<span class="string">&quot;192.168.25.128&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">constructor-arg</span> <span class="attr">name</span>=<span class="string">&quot;post&quot;</span>  <span class="attr">value</span>=<span class="string">&quot;7006&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;/<span class="name">set</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">constructor-arg</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">bean</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="&#x4EE3;&#x7801;&#x4F7F;&#x7528;"><a href="#&#x4EE3;&#x7801;&#x4F7F;&#x7528;" class="headerlink" title="&#x4EE3;&#x7801;&#x4F7F;&#x7528;"></a>&#x4EE3;&#x7801;&#x4F7F;&#x7528;</h3><h4 id="&#x6CE8;&#x610F;&#x65B0;&#x589E;&#x6216;&#x8005;&#x66F4;&#x65B0;&#x65F6;&#x5019;&#x5E94;&#x8BE5;&#x5220;&#x9664;&#x7F13;&#x5B58;&#x6570;&#x636E;&#xFF0C;&#x5B9E;&#x73B0;&#x7F13;&#x5B58;&#x540C;&#x6B65;"><a href="#&#x6CE8;&#x610F;&#x65B0;&#x589E;&#x6216;&#x8005;&#x66F4;&#x65B0;&#x65F6;&#x5019;&#x5E94;&#x8BE5;&#x5220;&#x9664;&#x7F13;&#x5B58;&#x6570;&#x636E;&#xFF0C;&#x5B9E;&#x73B0;&#x7F13;&#x5B58;&#x540C;&#x6B65;" class="headerlink" title="&#x6CE8;&#x610F;&#x65B0;&#x589E;&#x6216;&#x8005;&#x66F4;&#x65B0;&#x65F6;&#x5019;&#x5E94;&#x8BE5;&#x5220;&#x9664;&#x7F13;&#x5B58;&#x6570;&#x636E;&#xFF0C;&#x5B9E;&#x73B0;&#x7F13;&#x5B58;&#x540C;&#x6B65;"></a>&#x6CE8;&#x610F;&#x65B0;&#x589E;&#x6216;&#x8005;&#x66F4;&#x65B0;&#x65F6;&#x5019;&#x5E94;&#x8BE5;&#x5220;&#x9664;&#x7F13;&#x5B58;&#x6570;&#x636E;&#xFF0C;&#x5B9E;&#x73B0;&#x7F13;&#x5B58;&#x540C;&#x6B65;</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line">	<span class="function"><span class="keyword">public</span> List&lt;TbContent&gt; <span class="title">getContentListByCid</span><span class="params">(Long categoryId)</span> </span>{</span><br><span class="line">		<span class="comment">//&#x5148;&#x4ECE;redis&#x4E2D;&#x67E5;&#x627E;&#x7F13;&#x5B58;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x518D;&#x53BB;&#x4ECE;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x67E5;&#x627E;</span></span><br><span class="line">		<span class="keyword">try</span> {</span><br><span class="line">			String jsonData = jedisClient.hget(CONTENT_LIST, categoryId+<span class="string">&quot;&quot;</span>);</span><br><span class="line">			<span class="keyword">if</span>(StringUtils.isNotBlank(jsonData)){</span><br><span class="line">				List&lt;TbContent&gt; list = JsonUtils.jsonToList(jsonData, TbContent.class);</span><br><span class="line">				<span class="keyword">return</span> list ;</span><br><span class="line">			}</span><br><span class="line">		} <span class="keyword">catch</span> (Exception e) {</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		}</span><br><span class="line">		TbContentExample example = <span class="keyword">new</span> TbContentExample();</span><br><span class="line">		Criteria criteria = example.createCriteria();</span><br><span class="line">		criteria.andCategoryIdEqualTo(categoryId);</span><br><span class="line">		List&lt;TbContent&gt; list = tbContentMapper.selectByExampleWithBLOBs(example);</span><br><span class="line">		<span class="comment">//&#x67E5;&#x5230;&#x6570;&#x636E;&#x5E93;&#x540E;&#xFF0C;&#x518D;&#x4FDD;&#x5B58;&#x5230;&#x7F13;&#x5B58;&#x4E2D;&#x53BB;</span></span><br><span class="line">		<span class="keyword">try</span> {</span><br><span class="line">			jedisClient.hset(CONTENT_LIST, categoryId+<span class="string">&quot;&quot;</span>, JsonUtils.objectToJson(list));</span><br><span class="line">		} <span class="keyword">catch</span> (Exception e) {</span><br><span class="line">			e.printStackTrace();</span><br><span class="line">		}</span><br><span class="line">		<span class="keyword">return</span> list;</span><br><span class="line">	}</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> E3Result <span class="title">addContent</span><span class="params">(TbContent tbContent)</span> </span>{</span><br><span class="line">	tbContent.setCreated(<span class="keyword">new</span> Date());</span><br><span class="line">	tbContent.setUpdated(<span class="keyword">new</span> Date());</span><br><span class="line">	tbContentMapper.insert(tbContent);</span><br><span class="line">	<span class="comment">//&#x5B9E;&#x73B0;redis&#x7F13;&#x5B58;&#x540C;&#x6B65;&#xFF0C;&#x5220;&#x9664;redis&#x4E2D;&#x5BF9;&#x5E94;&#x7684;&#x952E;</span></span><br><span class="line">	jedisClient.hdel(CONTENT_LIST, tbContent.getCategoryId()+<span class="string">&quot;&quot;</span>);</span><br><span class="line">	<span class="keyword">return</span> E3Result.ok();</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/E3/" rel="tag"># E3</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/06/26/E3-Three/" rel="next" title="E3-Three">
                <i class="fa fa-chevron-left"></i> E3-Three
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/06/29/E3-Five/" rel="prev" title="E3-Five">
                E3-Five <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/me.jpg"
               alt="JokerLiang" />
          <p class="site-author-name" itemprop="name">JokerLiang</p>
          <p class="site-description motion-element" itemprop="description">永远年轻，永远热泪盈眶。</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">61</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/LoverJoker" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.zhihu.com/people/lover-easy-7/activities" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/2292572142/profile?rightmod=1&wvr=6&mod=personinfo" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  微博
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Friends
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.knight.ac.cn/" title="Knight" target="_blank">Knight</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://lzllzl.cn/" title="Zayvion" target="_blank">Zayvion</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://chen97.com/" title="Chens" target="_blank">Chens</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#redis安装方法"><span class="nav-number">1.</span> <span class="nav-text">redis安装方法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#安装redis需要c语言的编译环境"><span class="nav-number">1.1.</span> <span class="nav-text">安装redis需要c语言的编译环境</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#启动"><span class="nav-number">1.2.</span> <span class="nav-text">启动</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#redis集群的搭建"><span class="nav-number">2.</span> <span class="nav-text">redis集群的搭建</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#需要安装ruby的环境"><span class="nav-number">3.</span> <span class="nav-text">需要安装ruby的环境</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Jedis使用方法"><span class="nav-number">4.</span> <span class="nav-text">Jedis使用方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#项目中引入redis实现缓存"><span class="nav-number">5.</span> <span class="nav-text">项目中引入redis实现缓存</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Maven加入依赖"><span class="nav-number">5.1.</span> <span class="nav-text">Maven加入依赖</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#三个工具类"><span class="nav-number">5.2.</span> <span class="nav-text">三个工具类</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#JedisClient"><span class="nav-number">5.2.1.</span> <span class="nav-text">JedisClient</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#JedisClientCluster"><span class="nav-number">5.2.2.</span> <span class="nav-text">JedisClientCluster</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#JedisClientPool"><span class="nav-number">5.2.3.</span> <span class="nav-text">JedisClientPool</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Spring配置文件–可以随意切换是集群还是单个"><span class="nav-number">5.3.</span> <span class="nav-text">Spring配置文件–可以随意切换是集群还是单个</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#代码使用"><span class="nav-number">5.4.</span> <span class="nav-text">代码使用</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#注意新增或者更新时候应该删除缓存数据，实现缓存同步"><span class="nav-number">5.4.1.</span> <span class="nav-text">注意新增或者更新时候应该删除缓存数据，实现缓存同步</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">JokerLiang</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	




  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
      search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').toggle();
    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';
      $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = $( "entry", xmlResponse ).map(function() {
            return {
              title: $( "title", this ).text(),
              content: $("content",this).text(),
              url: $( "url" , this).text()
            };
          }).get();
          var $input = document.getElementById(search_id);
          var $resultContent = document.getElementById(content_id);
          $input.addEventListener('input', function(){
            var matchcounts = 0;
            var str='<ul class=\"search-result-list\">';
            var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
            $resultContent.innerHTML = "";
            if (this.value.trim().length > 1) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var content_index = [];
                var data_title = data.title.trim().toLowerCase();
                var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                var data_url = decodeURIComponent(data.url);
                var index_title = -1;
                var index_content = -1;
                var first_occur = -1;
                // only match artiles with not empty titles and contents
                if(data_title != '') {
                  keywords.forEach(function(keyword, i) {
                    index_title = data_title.indexOf(keyword);
                    index_content = data_content.indexOf(keyword);
                    if( index_title >= 0 || index_content >= 0 ){
                      isMatch = true;
                      if (i == 0) {
                        first_occur = index_content;
                      }
                    }

                  });
                }
                // show search results
                if (isMatch) {
                  matchcounts += 1;
                  str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                  var content = data.content.trim().replace(/<[^>]+>/g,"");
                  if (first_occur >= 0) {
                    // cut out 100 characters
                    var start = first_occur - 20;
                    var end = first_occur + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if(start == 0){
                      end = 50;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    var match_content = content.substring(start, end);
                    // highlight all keywords
                    keywords.forEach(function(keyword){
                      var regS = new RegExp(keyword, "gi");
                      match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                    });

                    str += "<p class=\"search-result\">" + match_content +"...</p>"
                  }
                  str += "</li>";
                }
              })};
            str += "</ul>";
            if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
            if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
            $resultContent.innerHTML = str;
          });
          proceedsearch();
        }
      });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".popoverlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>


  

  

  

  


</body>
</html>
